home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
x11
/
strategy
/
shanghai.000
/
shanghai
/
shanghai-1.0
/
makemap.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-24
|
9KB
|
209 lines
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OUTDATA "mapdata.c"
#define HEADER "mapdata.h"
#define NIL 255
typedef struct {
unsigned char index;
unsigned char x,y,depth;
unsigned char right[3],left[3];
unsigned char top[2],bottom[5];
unsigned char rdrw[10];
unsigned char shd0,shd1;
} Board;
static Board board[144];
static char def[8][15] = {
" 111111111111 ",
" 12222221 ",
" 1123333211 ",
"111123443211111",
" 111235432111 ",
" 1123333211 ",
" 12222221 ",
" 111111111111 "};
static unsigned char map[18][32][6];
static int compar(const void *b1,const void *b2)
{
return(((Board *)b1)->index-((Board *)b2)->index);
}
static void makeboard(FILE *out)
{
int x,y,i,j,k,count;
memset(board,NIL,sizeof(board));
memset(map,NIL,sizeof(map));
for (x = 15, i = 0; x--;)
for (y = 0; y < 8; y++)
if (def[y][x] != ' ') {
for (count = 0; count < def[y][x]-'0'; count++)
map[2*y][2*x][count] = i++; }
map[7][28][0] = map[6][28][0]; map[6][28][0] = NIL;
map[7][26][0] = map[6][26][0]; map[6][26][0] = NIL;
map[7][13][4] = map[8][12][4]; map[8][12][4] = NIL;
map[7][ 0][0] = map[6][ 0][0]; map[6][ 0][0] = NIL;
for (x = 30, i = 0; x--;)
for (y = 0; y < 16; y++)
for (count = 0; count < 5; count++)
if (map[y][x][count] != NIL) {
board[i].index = map[y][x][count];
board[i].x = x;
board[i].y = y;
board[i].depth = count;
k = 0;
if (x) {
if (y && map[y-1][x-2][count] != NIL)
board[i].left[k++] = map[y-1][x-2][count];
if (map[y+1][x-2][count] != NIL)
board[i].left[k++] = map[y+1][x-2][count];
board[i].left[k++] = map[y][x-2][count]; }
k = 0;
if (y && map[y-1][x+2][count] != NIL)
board[i].right[k++] = map[y-1][x+2][count];
if (map[y+1][x+2][count] != NIL)
board[i].right[k++] = map[y+1][x+2][count];
board[i].right[k++] = map[y][x+2][count];
if (count < 4 &&
(board[i].top[0] = map[y][x][count+1]) == NIL &&
(board[i].top[0] = map[y+1][x+1][count+1]) == NIL &&
(board[i].top[0] = map[y+1][x-1][count+1]) == NIL &&
(!y || (board[i].top[0] = map[y-1][x+1][count+1]) == NIL) &&
y)
board[i].top[0] = map[y-1][x-1][count+1];
if (count &&
(board[i].bottom[0] = map[y][x][count-1]) == NIL) {
board[i].bottom[0] = map[y-1][x+1][count-1];
board[i].bottom[1] = map[y+1][x+1][count-1];
board[i].bottom[2] = map[y-1][x-1][count-1];
board[i].bottom[3] = map[y+1][x-1][count-1]; }
j = 0;
if (y) {
if (map[y-2][x+2][0] != NIL)
for (k = 0;;k++) if (map[y-2][x+2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y-2][x+2][k];
break; } }
if (y) {
if (map[y-1][x+2][0] != NIL)
for (k = 0;;k++) if (map[y-1][x+2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y-1][x+2][k];
break; } }
if (map[y][x+2][0] != NIL)
for (k = 0;;k++) if (map[y][x+2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y][x+2][k];
break; }
if (map[y+1][x+2][0] != NIL)
for (k = 0;;k++) if (map[y+1][x+2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y+1][x+2][k];
break; }
if (map[y+2][x+2][0] != NIL)
for (k = 0;;k++) if (map[y+2][x+2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y+2][x+2][k];
break; }
if (y) {
if (map[y-2][x][0] != NIL)
for (k = 0;;k++) if (map[y-2][x][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y-2][x][k];
break; } }
for (k = 0; board[i].bottom[k] != NIL; k++)
board[i].rdrw[j++] = board[i].bottom[k];
if (map[y+2][x][0] != NIL)
for (k = 0;;k++) if (map[y+2][x][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y+2][x][k];
break; }
if (x) {
if (y) {
if (map[y-2][x-2][0] != NIL)
for (k = 0;;k++) if (map[y-2][x-2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y-2][x-2][k];
break; } }
if (y) {
if (map[y-1][x-2][0] != NIL)
for (k = 0;;k++) if (map[y-2][x-1][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y-1][x-2][k];
break; } }
if (map[y][x-2][0] != NIL)
for (k = 0;;k++) if (map[y][x-2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y][x-2][k];
break; }
if (map[y+2][x-2][0] != NIL)
for (k = 0;;k++) if (map[y+2][x-2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y+2][x-2][k];
break; }
if (map[y+1][x-2][0] != NIL)
for (k = 0;;k++) if (map[y+1][x-2][k+1]==NIL || k == count) {
board[i].rdrw[j++] = map[y+1][x-2][k];
break; } }
if (y) {
board[i].shd0 = map[y-2][x][count];
if ((board[i].shd1 = map[y-2][x+2][count]) == NIL)
board[i].shd1 = map[y-1][x+2][count]; }
i++; }
if (i != 144)
fprintf(out,"#error count != 144\n");
qsort(board,144,sizeof(Board),compar);
fprintf(out,"\nBoard board[144] = {\n");
for (i = 0; i < 144; i++)
fprintf(out,"/* %3d */ " /* index */
"{%2d,%2d,%1d," /* x,y,d */
"{%3d,%3d,%3d},{%3d,%3d,%3d}," /* r[3],l[3]*/
"%3d,%3d,"/*"{%3d,%3d,%3d,%3d,%3d},"*//* t[2],b[5]*/
/* "{%3d,%3d,%3d,%3d,%3d}," */ /* rd[10] */
/* "{%3d,%3d,%3d,%3d,%3d}," */ /* rd[10] */
"%3d,%3d}%s\n", /* shd0,shd1*/
board[i].index,
board[i].x,board[i].y,board[i].depth,
board[i].right[0],board[i].right[1],board[i].right[2],
board[i].left[0],board[i].left[1],board[i].left[2],
board[i].top[0],/*board[i].top[1],*/
board[i].bottom[0],/*board[i].bottom[1],
board[i].bottom[2],board[i].bottom[3],
board[i].bottom[4],*/
/* board[i].rdrw[0],board[i].rdrw[1],
board[i].rdrw[2],board[i].rdrw[3],
board[i].rdrw[4],board[i].rdrw[5],
board[i].rdrw[6],board[i].rdrw[7],
board[i].rdrw[8],board[i].rdrw[9], */
board[i].shd0,board[i].shd1,
i == 143 ? "};" : ",");
return;
}
int main(void)
{
FILE /* *inp, */ *out,*hdr;
if ((hdr = fopen(HEADER,"w")) == NULL ||
(out = fopen(OUTDATA,"w")) == NULL) {
return(1); }
fprintf(out,"#include \"mapdata.h\"\n"
"\n");
makeboard(out);
fprintf(hdr,"#ifndef __MAP_DATA__\n"
"#define __MAP_DATA__\n"
"\n"
"#define NIL\t255\n"
"\n"
"typedef struct {\n"
"\tunsigned char\t\tx,y,depth;\n"
"\tunsigned char\t\tright[3],left[3];\n"
"\tunsigned char\t\ttop,bottom;\n"
"\tunsigned char\t\tshd0,shd1;\n"
"} Board;\n"
"\n"
"extern Board board[144];\n"
"\n"
"#endif\n");
fclose(out);
fclose(hdr);
return(0);
}